﻿using Application.Permissions.Interfaces;
using Application.Permissions.Models;
using Microsoft.AspNetCore.Mvc;
using Shared.Http.APIResult;

namespace WebApi.Controllers
{
    [Route("api/v1/[controller]/[action]")]
    public class PermissionServiceController(IPermissionService manager) : ControllerBase
    {
        [HttpGet]
        public async Task<ActionResult<IReadOnlyList<PermissionGroup>>> GetAll()
        {
            IReadOnlyList<PermissionGroup>? result = manager.GetAll();

            var data = ApiResult.Success(result, Guid.NewGuid().ToString());
            return Ok(data);
        }

        [HttpGet]
        public async Task<ActionResult<ApiResult<PermissionDto>>> GetBySign(string sign)
        {
            var result = manager.GetBySign(sign);

            return Ok(ApiResult.Success(result, Guid.NewGuid().ToString()));
        }

        [HttpGet]
        public async Task<ActionResult<ApiResult<bool>>> IsValidSign(string sign)
        {
            bool result = manager.IsValidSign(sign);

            return Ok(ApiResult.Success(result, Guid.NewGuid().ToString()));
        }

        [HttpPost]
        public async Task<IActionResult> Reload()
        {
            await manager.ReloadAsync();

            return Ok();
        }
    }
}
